package com.simple.gateway.core.datasource.unpooled;

import com.simple.gateway.core.datasource.DataSource;
import com.simple.gateway.core.datasource.DataSourceFactory;
import com.simple.gateway.core.mapping.HttpStatement;
import com.simple.gateway.core.session.Configuration;

/**
 * 项目: simple-gateway-core
 *
 * 功能描述: 无池化数据源工厂
 *
 * @author: WuChengXing
 *
 * @create: 2023-08-04 17:00
 **/
public class UnpooledDataSourceFactory implements DataSourceFactory {

    protected UnpooledDataSource dataSource;

    public UnpooledDataSourceFactory() {
        this.dataSource = new UnpooledDataSource();
    }

    @Override
    public void setProperties(Configuration configuration, String uri) {
        this.dataSource.setConfiguration(configuration);
        HttpStatement httpStatement = configuration.getHttpStatement(uri);
        this.dataSource.setDataSourceType(httpStatement.getDataSourceType());
        this.dataSource.setHttpStatement(configuration.getHttpStatement(uri));
    }

    @Override
    public DataSource getDataSource() {
        return dataSource;
    }

}
